package com.douwong.student.factory;

import com.douwong.student.base.BaseFragment;
import com.douwong.student.fragment.ApplicationFragment;
import com.douwong.student.fragment.ClassFragment;
import com.douwong.student.fragment.HomeFragment;
import com.douwong.student.fragment.StudyFragment;
import com.douwong.student.utils.LogUtils;

import java.util.HashMap;
import java.util.Map;

/**
 * @autor yichao
 * @time 2017/4/2013:45
 * @des 主页fragment的工厂类
 */
public class BaseFragmentFactory {
    private static final String TAG = "BaseFragmentFactory";
    private final static int home_fragment=0;
    private final static int Class_fragment=1;
    private  final static int Application_fragment=2;
    private final static int Study_fragment=3;

    private static Map<Integer, BaseFragment> sMap = new HashMap<>();

    public static BaseFragment getBaseFragment(int position) {
        BaseFragment baseFragment = null;
        if (sMap.containsKey(position)){
            baseFragment=     sMap.get(position);
            LogUtils.i(TAG,"创建fragment  的位置，"+position+" 缓存 创建 ");
        }else {

            switch (position) {
                case home_fragment:
                    baseFragment = new HomeFragment();
                    break;
                case Class_fragment:
                    baseFragment = new ClassFragment();
                    break;
                case Application_fragment:
                    baseFragment = new ApplicationFragment();
                    break;
                case Study_fragment:
                    baseFragment = new StudyFragment();
                    break;
            }
            LogUtils.i(TAG,"创建fragment  的位置，"+position+" 第一次 创建 ");
            sMap.put(position,baseFragment);
        }
        return baseFragment;
    }


}
